<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//echo $this->layout()->variable;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>CMS - Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!--// FOLLOWING SCRIPT IS FOR PNG FIX IE5.5/IE6-->
    

<!--[if lt IE 7]>
<script defer type="text/javascript" src="js/pngfix.js"></script> 
<![endif]--> 


<!--//  Styles starts -->


<link href="/css/estilos.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="/css/system/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
  <script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="/js/jquery-ui-1.8.custom.min.js"></script>
        <script type="text/javascript" src="/js/i18n/ui.datepicker-es.js"></script>
        <script type="text/javascript" src="/js/jquery.corner.js"></script>
        <script type="text/javascript" src="/js/jquery.validate.min.js"></script>
        <script type="text/javascript" src="/js/jquery.metadata.js"></script>
        <script type="text/javascript" src="/js/jquery.rater.js"></script>
        <script type="text/javascript" src="/js/jquery.cookie.js"></script>
        <script type="text/javascript" src="/js/commons.js"></script>
        <script type="text/javascript" src="/js/jquery.cycle.all.js"></script>
        <script type="text/javascript" src="/js/system_lib.js"></script>


<script type="text/javascript">
	$(document).ready(function() {
		$("button, input:submit").button();	
		email = $("#email");
		allFields = $([]).add(email);
		
		tips = $("#validateTips");

		$("#forgetPassword").click( 
				function() 
				{ 
				 $(":button:contains('Enviar')").show(); // si el dialogo se cerro antes, entonces tengo que mostrar el boton 
				 $("#dialog fieldset").show(); 	 // si el dialogo se cerro antes entonces tengo que mostrar el formulario
				 $('#dialog').dialog('open')
				});	

		function updateTips(t) {
			tips.text(t).effect("highlight",{},1500);
		}
		
		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Length of " + n + " must be between "+min+" and "+max+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}


		$("#dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			width: 300,
			modal: true,
			title : '<?=$this->t->_('Recuperar_Password') ?>',
			buttons: {
				'Enviar': function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					//bValid = bValid && checkLength(email,"email",6,80);
					bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Dirección de mail no válida");

					$.get("/system/user/existsuser?email="+email.val(),function(data)
					{
						if (bValid) 
						{
							if ( data == 1 )
							{
								$('#users tbody').append('<tr>' + 
									'<td>' + email.val() + '</td>' + 
									'</tr>');
								/*
								* si el mail es válido, envio la peticion por get para que cambie el password 
								* y lo mande por mail.
								*/
								$.get("/system/user/recoverypassword?email="+email.val());
						 
								/*
								* Oculto el formulario y el boton enviar una vez realizado el envio del email
								* Y cambio el texto del dialogo	
								*/
								$(":button:contains('Enviar')").hide();   
								$("#dialog fieldset").hide(); 
								updateTips('<?=$this->t->_('Se_ha_enviado_un_email_con_tu_nueva_contrasenia')?>');
							}
							else
							{
								email.addClass('ui-state-error');
								updateTips('<?=$this->t->_('No_existe_un_usuario_con_ese_email')?>');
							}
						}	
					});
					
					
				},
				'Cerrar': function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
				updateTips('<?=$this->t->_('Completa_tu_email_y_recibiras_un_email_con_tu_nueva_contrasenia')?>');
			}
		});
		
		
	 });
	</script>
</head>
<body>

<div class="box">
	<div class="welcome" id="welcometitle"><img style="width : 190px;"  src="/images/logo1.png"> <!--//  Welcome message -->
</div>
  
  
  <div id="fields"> 
    <?=$this->form ?>
    <?if($this->errorLogin):?>
    	<div class="errorMessage"><p>La clave es erronea o bien el email no se encuentra registrado</p></div>
    <?endif?>
  </div>
  
  
  <div class="login" id="lostpassword">
  	<a href="#" id="forgetPassword" ><?=$this->t->_('Olvido_su_contrasenia') ?></a>

  	
<div id="dialog" >
<p id="validateTips"><?=$this->t->_('Completa_tu_email_y_recibiras_un_email_con_tu_nueva_contrasenia')?></p>
	<fieldset style="border : none;">
		<label for="email">Email</label>
		<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" style="width : 200px;" />
	</fieldset>
</div>
  	
  	</div> <!--//  lost password part -->
  	
 </div>


</body>

</html>
